home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 401-425 / disk_419 / yacc / src.lzh / Src / defs.h < prev    next >
C/C++ Source or Header  |  1990-07-14  |  6KB  |  290 lines

  1. #include <assert.h>
  2. #include <ctype.h>
  3. #include <stdio.h>
  4.  
  5.  
  6. /*  machine dependent definitions            */
  7. /*  the following definitions are for the VAX        */
  8. /*  they might have to be changed for other machines    */
  9.  
  10. /*  MAXCHAR is the largest unsigned character value    */
  11. /*  MAXSHORT is the largest value of a C short        */
  12. /*  MINSHORT is the most negative value of a C short    */
  13. /*  MAXTABLE is the maximum table size            */
  14. /*  BITS_PER_WORD is the number of bits in a C unsigned    */
  15. /*  WORDSIZE computes the number of words needed to    */
  16. /*    store n bits                    */
  17. /*  BIT returns the value of the n-th bit starting    */
  18. /*    from r (0-indexed)                */
  19. /*  SETBIT sets the n-th bit starting from r        */
  20.  
  21. #define    MAXCHAR        255
  22. #define    MAXSHORT    32767
  23. #define MINSHORT    -32768
  24. #define MAXTABLE    32500
  25. #define BITS_PER_WORD    32
  26. #define    WORDSIZE(n)    (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  27. #define    BIT(r, n)    ((((r)[(n)>>5])>>((n)&31))&1)
  28. #define    SETBIT(r, n)    ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
  29.  
  30.  
  31. /*  character names  */
  32.  
  33. #define    NUL        '\0'    /*  the null character  */
  34. #define    NEWLINE        '\n'    /*  line feed  */
  35. #define    SP        ' '     /*  space  */
  36. #define    BS        '\b'    /*  backspace  */
  37. #define    HT        '\t'    /*  horizontal tab  */
  38. #define    VT        '\013'  /*  vertical tab  */
  39. #define    CR        '\r'    /*  carriage return  */
  40. #define    FF        '\f'    /*  form feed  */
  41. #define    QUOTE        '\''    /*  single quote  */
  42. #define    DOUBLE_QUOTE    '\"'    /*  double quote  */
  43. #define    BACKSLASH    '\\'    /*  backslash  */
  44.  
  45.  
  46. /* defines for constructing filenames */
  47.  
  48. #define    DEFINES_SUFFIX    ".tab.h"
  49. #define    OUTPUT_SUFFIX    ".tab.c"
  50. #define    VERBOSE_SUFFIX    ".output"
  51.  
  52.  
  53. /* keyword codes */
  54.  
  55. #define TOKEN 0
  56. #define LEFT 1
  57. #define RIGHT 2
  58. #define NONASSOC 3
  59. #define MARK 4
  60. #define TEXT 5
  61. #define TYPE 6
  62. #define START 7
  63. #define UNION 8
  64. #define IDENT 9
  65.  
  66.  
  67. /*  symbol classes  */
  68.  
  69. #define UNKNOWN 0
  70. #define TERM 1
  71. #define NONTERM 2
  72.  
  73.  
  74. /*  the undefined value  */
  75.  
  76. #define UNDEFINED (-1)
  77.  
  78.  
  79. /*  action codes  */
  80.  
  81. #define SHIFT 1
  82. #define REDUCE 2
  83. #define ERROR 3
  84.  
  85.  
  86. /*  character macros  */
  87.  
  88. #define IS_IDENT(c)    (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  89. #define    IS_OCTAL(c)    ((c) >= '0' && (c) <= '7')
  90. #define    NUMERIC_VALUE(c)    ((c) - '0')
  91.  
  92.  
  93. /*  symbol macros  */
  94.  
  95. #define ISTOKEN(s)    ((s) < start_symbol)
  96. #define ISVAR(s)    ((s) >= start_symbol)
  97.  
  98.  
  99. /*  storage allocation macros  */
  100.  
  101. #define CALLOC(k,n)    (calloc((unsigned)(k),(unsigned)(n)))
  102. #define    FREE(x)        (free((char*)(x)))
  103. #define MALLOC(n)    (malloc((unsigned)(n)))
  104. #define    NEW(t)        ((t*)allocate(sizeof(t)))
  105. #define    NEW2(n,t)    ((t*)allocate((unsigned)((n)*sizeof(t))))
  106. #define REALLOC(p,n)    (realloc((char*)(p),(unsigned)(n)))
  107.  
  108.  
  109. /*  the structure of a symbol table entry  */
  110.  
  111. typedef struct bucket bucket;
  112. struct bucket
  113. {
  114.     struct bucket *link;
  115.     struct bucket *next;
  116.     char *name;
  117.     char *tag;
  118.     short value;
  119.     short index;
  120.     short prec;
  121.     char class;
  122.     char assoc;
  123. };
  124.  
  125.  
  126. /*  the structure of the LR(0) state machine  */
  127.  
  128. typedef struct core core;
  129. struct core
  130. {
  131.     struct core *next;
  132.     struct core *link;
  133.     short number;
  134.     short accessing_symbol;
  135.     short nitems;
  136.     short items[1];
  137. };
  138.  
  139.  
  140. /*  the structure used to record shifts  */
  141.  
  142. typedef struct shifts shifts;
  143. struct shifts
  144. {
  145.     struct shifts *next;
  146.     short number;
  147.     short nshifts;
  148.     short shift[1];
  149. };
  150.  
  151.  
  152. /*  the structure used to store reductions  */
  153.  
  154. typedef struct reductions reductions;
  155. struct reductions
  156. {
  157.     struct reductions *next;
  158.     short number;
  159.     short nreds;
  160.     short rules[1];
  161. };
  162.  
  163.  
  164. /*  the structure used to represent parser actions  */
  165.  
  166. typedef struct action action;
  167. struct action
  168. {
  169.     struct action *next;
  170.     short symbol;
  171.     short number;
  172.     short prec;
  173.     char action_code;
  174.     char assoc;
  175.     char suppressed;
  176. };
  177.  
  178.  
  179. /* global variables */
  180.  
  181. extern char dflag;
  182. extern char lflag;
  183. extern char tflag;
  184. extern char vflag;
  185.  
  186. extern char *myname;
  187. extern char *cptr;
  188. extern char *line;
  189. extern int lineno;
  190. extern int outline;
  191.  
  192. extern char *banner[];
  193. extern char *header[];
  194. extern char *body[];
  195. extern char *trailer[];
  196.  
  197. extern char *action_file_name;
  198. extern char *defines_file_name;
  199. extern char *input_file_name;
  200. extern char *output_file_name;
  201. extern char *text_file_name;
  202. extern char *union_file_name;
  203. extern char *verbose_file_name;
  204.  
  205. extern FILE *action_file;
  206. extern FILE *defines_file;
  207. extern FILE *input_file;
  208. extern FILE *output_file;
  209. extern FILE *text_file;
  210. extern FILE *union_file;
  211. extern FILE *verbose_file;
  212.  
  213. extern int nitems;
  214. extern int nrules;
  215. extern int nsyms;
  216. extern int ntokens;
  217. extern int nvars;
  218. extern int ntags;
  219.  
  220. extern char unionized;
  221. extern char line_format[];
  222.  
  223. extern int   start_symbol;
  224. extern char  **symbol_name;
  225. extern short *symbol_value;
  226. extern short *symbol_prec;
  227. extern char  *symbol_assoc;
  228.  
  229. extern short *ritem;
  230. extern short *rlhs;
  231. extern short *rrhs;
  232. extern short *rprec;
  233. extern char  *rassoc;
  234.  
  235. extern short **derives;
  236. extern char *nullable;
  237.  
  238. extern bucket *first_symbol;
  239. extern bucket *last_symbol;
  240.  
  241. extern int nstates;
  242. extern core *first_state;
  243. extern shifts *first_shift;
  244. extern reductions *first_reduction;
  245. extern short *accessing_symbol;
  246. extern core **state_table;
  247. extern shifts **shift_table;
  248. extern reductions **reduction_table;
  249. extern unsigned *LA;
  250. extern short *LAruleno;
  251. extern short *lookaheads;
  252. extern short *goto_map;
  253. extern short *from_state;
  254. extern short *to_state;
  255.  
  256. extern action **parser;
  257. extern int SRtotal;
  258. extern int RRtotal;
  259. extern short *SRconflicts;
  260. extern short *RRconflicts;
  261. extern short *defred;
  262. extern short *rules_used;
  263. extern short nunused;
  264. extern short final_state;
  265.  
  266. /* global functions */
  267.  
  268. extern char *allocate();
  269. extern bucket *lookup();
  270. extern bucket *make_bucket();
  271.  
  272.  
  273. /* system variables */
  274.  
  275. extern int errno;
  276.  
  277.  
  278. /* system functions */
  279.  
  280. extern void free();
  281. extern char *calloc();
  282. #ifdef AMIGA
  283. extern void *malloc();
  284. extern void *realloc();
  285. #else
  286. extern char *malloc();
  287. extern char *realloc();
  288. #endif
  289. extern char *strcpy();
  290.